//C06:MergeTest.cpp
// Test merging in sorted ranges.
// {L} Generators
#include <algorithm>
#include "PrintSequence.h"
#include "Generators.h"
using namespace std;

int main(void)
{
    const int SZ = 15;
    int a[SZ * 2] = {0};
    // Both ranges go in the same array:
    generate(a, a + SZ, SkipGen(0,2));
    a[3] = 4;
    a[4] = 4;
    generate(a, a + SZ, SkipGen(1,3));
    print(a, a + SZ, "range1", " ");
    print(a + SZ, a + SZ * 2, "range2", " ");
    int b[SZ * 2] = {0};    // Initialize all to zero
    merge(a, a + SZ, a + SZ, a + SZ * 2, b);
    print(b, b + SZ * 2, "merge", " ");
    // Reset b
    for(int i = 0; i < 5; i++)
    {
        b[i] = 0;
    }
    inplace_merge(a, a + SZ, a + SZ * 2);
    print(a ,a + SZ * 2, "inplace_merge", " ");
    int* end = set_union(a, a + SZ, a + SZ, a + SZ * 2, b);
    print(b, end, "set_union", " ");
}